package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.CourseSchedulingDetail;
import com.xmy.cultivate.entity.LackCourseLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 缺课记录 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-03-20
 */
public interface LackCourseLogMapper extends BaseMapper<LackCourseLog> {

    @Select({
            "<script>",
            "SELECT",
            "t01.* ",
            "FROM",
            "lack_course_log AS t01",
            "INNER JOIN course_scheduling_always AS t02 ",
            "WHERE",
            "t01.`year_part` = ${yearPart} ",
            "AND t01.`quarter_num` = ${quarterNum} ",
            "AND t01.subjects_id = ${subjectsId} ",
            "AND t01.lesson_type = 1 ",
            "AND t01.student_id = ${studentId} ",
            "AND t02.num = ${lessonNum} ",
            "AND t01.deleted = 0",
            "</script>"
    })
    public abstract LackCourseLog getLackCoruseLogForStudent(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("studentId") Long studentId, @Param("subjectsId") Long subjectsId, @Param("lessonNum") Integer lessonNum);


    /**
     * 获取一条数据，包含删除的
     * @param Id
     * @return
     */
    @Select("select * from lack_course_log where id=${Id}")
    public abstract LackCourseLog getOneForId(@Param("Id") Long Id);

    @Select("select * from lack_course_log where out_id=${OutId} limit 1")
    public abstract LackCourseLog getOneForOutId(@Param("OutId") Long OutId);

    @Update("update lack_course_log set deleted= ${deleted} where id = ${id}")
    public Integer updateDeleted(@Param("id") Long id,@Param("deleted") Integer deleted);

}
